package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysFinanceLog;
import com.ruoyi.system.service.ISysFinanceLogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 财务资金Controller
 *
 * @author ruoyi
 * @date 2022-01-28
 */
@RestController
@RequestMapping("/system/log")
public class SysFinanceLogController extends BaseController {

  @Autowired
  private ISysFinanceLogService sysFinanceLogService;

  /**
   * 查询财务资金列表
   */
  @GetMapping("/list")
  public TableDataInfo list(SysFinanceLog sysFinanceLog) {
    startPage();
    List<SysFinanceLog> list = sysFinanceLogService.selectSysFinanceLogList(sysFinanceLog);
    return getDataTable(list);
  }

  /**
   * 导出财务资金列表
   */
  @Log(title = "财务资金", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  public void export(HttpServletResponse response, SysFinanceLog sysFinanceLog) {
    List<SysFinanceLog> list = sysFinanceLogService.selectSysFinanceLogList(sysFinanceLog);
    ExcelUtil<SysFinanceLog> util = new ExcelUtil<SysFinanceLog>(SysFinanceLog.class);
    util.exportExcel(response, list, "财务资金数据");
  }

  /**
   * 获取财务资金详细信息
   */
  @GetMapping(value = "/{financeId}")
  public AjaxResult getInfo(@PathVariable("financeId") Long financeId) {
    return AjaxResult.success(sysFinanceLogService.selectSysFinanceLogByFinanceId(financeId));
  }

  /**
   * 新增财务资金
   */
  @Log(title = "财务资金", businessType = BusinessType.INSERT)
  @PostMapping
  public AjaxResult add(@RequestBody SysFinanceLog sysFinanceLog) {
    return toAjax(sysFinanceLogService.insertSysFinanceLog(sysFinanceLog));
  }

  /**
   * 修改财务资金
   */
  @Log(title = "财务资金", businessType = BusinessType.UPDATE)
  @PutMapping
  public AjaxResult edit(@RequestBody SysFinanceLog sysFinanceLog) {
    return toAjax(sysFinanceLogService.updateSysFinanceLog(sysFinanceLog));
  }

  /**
   * 删除财务资金
   */
  @Log(title = "财务资金", businessType = BusinessType.DELETE)
  @DeleteMapping("/{financeIds}")
  public AjaxResult remove(@PathVariable Long[] financeIds) {
    return toAjax(sysFinanceLogService.deleteSysFinanceLogByFinanceIds(financeIds));
  }
}
